package com.cn.kehong.controller;



import com.cn.kehong.api.IUserRouterService;
import com.cn.kehong.domain.UserRouter;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/router")
public class LoginRouterController {

    @Autowired
    private IUserRouterService userRouterService;

    @RequestMapping("/queryUserRouterList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<UserRouter>> queryUserRouterList(QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<UserRouter>> response = new JsonResponse<List<UserRouter>>();
        List<UserRouter> list  = userRouterService.selectUserRouters(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }


    @ResponseBody
    @RequestMapping("/addUserRouter/{frontToken}")
    public JsonResponse<String> addUserRouter(@RequestBody UserRouter userRouter, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = userRouterService.addUserRouter(userRouter);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateUserRouter/{frontToken}")
    public JsonResponse<String> updateUserRouter(UserRouter userRouter,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = userRouterService.updateUserRouter(userRouter);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deleteUserRouter/{frontToken}")
    public JsonResponse<String> deleteUserRouter(String id,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = userRouterService.deleteUserRouter(id);
        return CommonUtil.getResponseData(response,result);
    }

}
